package org.alex.nettychat.netty.learn.learn3;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.nio.charset.StandardCharsets;

/**
 * @author : alex
 */
public class FirstClientHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        for (int i=0;i<1000;i++) {
            ByteBuf byteBuf = getBuffer(ctx);
            ctx.channel().writeAndFlush(byteBuf);
        }
    }

    private ByteBuf getBuffer(ChannelHandlerContext ctx) {
        byte[] bytes = "你好123456765431234123".getBytes(StandardCharsets.UTF_8);

        ByteBuf buffer = ctx.alloc().buffer();
        buffer.writeBytes(bytes);

        return buffer;
    }
}
